/*
 * Copyright (C) 2010 The Android Open Source Project
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 */

package com.tony.demo.pinnedlistview;

import android.app.ListActivity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.tony.demo.R;

/**
 * An activity that demonstrates various use cases for the {@link PinnedHeaderListView}.
 */
public class PinnedHeaderUseCaseActivity extends ListActivity {

	 private static final int SINGLE_SHORT_SECTION_NO_HEADERS = 0;
	 private static final int TWO_SHORT_SECTIONS_WITH_HEADERS = 1;
	 private static final int FIVE_SHORT_SECTIONS_WITH_HEADERS = 2;
//	private static final int SINGLE_SHORT_SECTION_NO_HEADERS_lbt = 3;
//	private static final int TWO_SHORT_SECTIONS_WITH_HEADERS_lbt = 4;
//	private static final int FIVE_SHORT_SECTIONS_WITH_HEADERS_lbt = 5;
	private String[] mItems = { /* "SINGLE_SHORT_SECTION_NO_HEADERS", "TWO_SHORT_SECTIONS_WITH_HEADERS", "FIVE_SHORT_SECTIONS_WITH_HEADERS", */"SINGLE_SHORT_SECTION_NO_HEADERS_lbt",
			"TWO_SHORT_SECTIONS_WITH_HEADERS_lbt", "FIVE_SHORT_SECTIONS_WITH_HEADERS_lbt" };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setListAdapter(new ArrayAdapter<String>(this, R.layout.intent_list_item, mItems));
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		switch (position) {
		// case SINGLE_SHORT_SECTION_NO_HEADERS:
		// startActivity(new int[] { 5 }, new String[] { "Line" }, new boolean[] { false }, new boolean[] { false }, new int[] { 0 });
		// break;
		// case TWO_SHORT_SECTIONS_WITH_HEADERS:
		// startActivity(new int[] { 2, 30 }, new String[] { "First", "Second" }, new boolean[] { true, true }, new boolean[] { false, false }, new int[] { 0, 2000 });
		// break;
		// case FIVE_SHORT_SECTIONS_WITH_HEADERS:
		// startActivity(new int[] { 1, 5, 5, 5, 5 }, new String[] { "First", "Second", "Third", "Fourth", "Fifth" }, new boolean[] { true, true, true, true, true }, new boolean[] { false,
		// false, false, false, false }, new int[] { 0, 1000, 1000, 2000, 2000 });
		// break;
			case SINGLE_SHORT_SECTION_NO_HEADERS:
				startActivity_lbt(new int[] { 5 }, new String[] { "Line" }, new boolean[] { false }, new boolean[] { false }, new int[] { 0 });
				break;
			case TWO_SHORT_SECTIONS_WITH_HEADERS:
				startActivity_lbt(new int[] { 2, 30, 15 }, new String[] { "First", "Second", "Third" }, new boolean[] { true, true, false }, new boolean[] { false, false, true }, new int[] { 0, 2000, 0 });
				break;
			case FIVE_SHORT_SECTIONS_WITH_HEADERS:
				startActivity_lbt(new int[] { 5, 15, 10, 10, 20 }, new String[] { "First", "Second", "Third", "Fourth", "Fifth" }, new boolean[] { true, true, false, true, true }, new boolean[] { false,
						false, false, false, false }, new int[] { 0, 1000, 1000, 2000, 2000 });
				break;
		}
	}

	// private void startActivity(int[] counts, String[] names, boolean[] headers, boolean[] showIfEmpty, int[] delays) {
	// Intent intent = new Intent();
	// intent.setComponent(new ComponentName("com.android.contacts", "com.android.contacts.widget.PinnedHeaderListDemoActivity"));
	// intent.putExtra("counts", counts);
	// intent.putExtra("names", names);
	// intent.putExtra("headers", headers);
	// intent.putExtra("showIfEmpty", showIfEmpty);
	// intent.putExtra("delays", delays);
	//
	// startActivity(intent);
	// }

	private void startActivity_lbt(int[] counts, String[] names, boolean[] headers, boolean[] showIfEmpty, int[] delays) {
		Intent intent = new Intent();
		intent.setComponent(new ComponentName("com.tony", "com.tony.demo.pinnedlistview.PinnedHeaderListDemoActivity"));
		intent.putExtra("counts", counts);
		intent.putExtra("names", names);
		intent.putExtra("headers", headers);
		intent.putExtra("showIfEmpty", showIfEmpty);
		intent.putExtra("delays", delays);

		startActivity(intent);
	}
}
